//
//  HomepagePopView.m
//  Unity-iPhone
//
//  Created by Karl on 2017/3/28.
//
//

#import "HomepagePopView.h"
#import "ButtomLogoView.h"

@implementation HomepagePopView{
    
    UIButton *_closeBtn;
    UIButton *_detailBtn;
    UIImageView *_infoView;    
}

- (instancetype)init{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:142.0/255.0 green:176.0/255.0 blue:198.0/255.0 alpha:1.0];
        
        _closeBtn = [UIButton new];
        [_closeBtn setBackgroundImage:[UIImage imageNamed:@"all_close"] forState:UIControlStateNormal];
        [_closeBtn addTarget:self action:@selector(closeBtnOnPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_closeBtn];
        
        _infoView = [UIImageView new];
        [_infoView setImage:kImgFromFile(Babel(@"home_pop_bg"), @"png")];
        [self addSubview:_infoView];
        
        _detailBtn = [UIButton new];
        [_detailBtn setBackgroundImage:kImgFromFile(Babel(@"home_pop_btn"), @"png") forState:UIControlStateNormal];
        [_detailBtn addTarget:self action:@selector(detailBtnOnPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_detailBtn];
        
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat scale = 1.0;
    if (isPad) {
        scale = SizeScaleX;
    }else{
        scale = SizeScaleY;
    }
    
    _closeBtn.width = 30.0;
    _closeBtn.height = 30.0;
    _closeBtn.top = self.top + 6.7;
    _closeBtn.right  =self.right - 6.7;
    
    _infoView.top  = self.top + 40  * scale;
    _infoView.left = 48 * scale;
    _infoView.width = self.width - 96 * scale;
    _infoView.height =244 * scale;
    
//    NSLog(@"%@",[NSValue valueWithCGRect:_infoView.frame]);
    
    _detailBtn.centerX  =self.width / 2;
    _detailBtn.width = 218.7 * scale;
    _detailBtn.height = 49.7 * scale;
    _detailBtn.top = _infoView.bottom + 6.7 * scale;
    
}

- (void)closeBtnOnPressed:(id)sender{
    NSLog(@"close pop");
    [self setHidden:YES];
}

- (void)detailBtnOnPressed:(id)sender{
    NSLog(@"go to pop detail");
    [[NativeViewManager sharedManager] showWebWithURL:Babel(@"home_pop_url") inApp:NO];
}

@end
